﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameworkManapro.BusinessModel;

namespace GMAC.ReportingSystem.Business.Entities
{
    //-------------------------------------------------
    /// <summary>
    /// Ricardo Recaredo (31/03/2011)
    /// 
    /// Re-Purchase History Class
    /// </summary>
    //-------------------------------------------------

    [Serializable]
    [DbProcedures(Insert = "procHistoricRePurchaseInsert", Update = "procHistoricRePurchaseUpdate", Delete = "procHistoricRePurchaseDelete")]

    public class HistoricRePurchase : BusinessEntity
    {
        #region Properties

        public int     Id                 { get; set; }

        [EntityPrimaryKey]
        [DbParameter(1, 1, 1)]
        public int     LiquidationYear    { get; set; }

        [DbParameter(2, 2, 0)]
        public decimal TotalCreditCleared { get; set; }

        [DbParameter(0, 0, 0)]
        public decimal Remnant            { get; set; }

        [DbParameter(3, 3, 0)]
        public decimal PercentageApplied  { get; set; }

        [DbParameter(4, 4, 0)]
        public decimal Repurchase         { get; set; }

        [DbParameter(5, 5, 0)]
        public decimal TotalBsCleared_ { get; set; }

        [DbParameter(0, 0, 0)]
        public decimal PercentClearedCredit_ { get; set; }
        
        #endregion

        //---------------------------------------------------

        #region Dynamic Properties

        public Others.DynamicProperty<decimal> TotalBsCleared       { get; set; }
        public Others.DynamicProperty<decimal> PercentClearedCredit { get; set; }

        #endregion

        //---------------------------------------------------

        #region Constructors

        public HistoricRePurchase()
        {
            TotalBsCleared       = new Others.DynamicProperty<decimal>();
            PercentClearedCredit = new Others.DynamicProperty<decimal>();

            this.TotalBsCleared.PropertyChange += (x) =>
            {
                this.TotalBsCleared_          = this.TotalBsCleared.val;
                this.PercentClearedCredit.val = (this.TotalBsCleared.val * this.PercentageApplied) / ((decimal)100.00);
            };

            //---------

            this.PercentClearedCredit.PropertyChange += (x) =>
            {
                this.PercentClearedCredit_ = this.PercentClearedCredit.val;
                this.Remnant               = this.PercentClearedCredit.val - this.Repurchase;
            };
        }

        #endregion
    }

    //-------------------------------------------
    /// <summary>
    /// Collection of HistoricRePurchase for listing.
    /// </summary>
    //-------------------------------------------

    public class HistoricRePurchaseCollection : List<HistoricRePurchase>
    {
        public int TotalResults { get; set; }
    }

    //-------------------------------------------

    public class Years : List<int>
    {
    }
}
